package logic

import (
	"autotestservice/testservices/internal/data"
	"context"
	"gitee.com/jmdvirus/jkgo/jk/jklog"

	"autotestservice/testservices/internal/svc"
	"autotestservice/testservices/internal/types"

	"github.com/tal-tech/go-zero/core/logx"
)

type AutotestserviceLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAutotestserviceLogic(ctx context.Context, svcCtx *svc.ServiceContext) AutotestserviceLogic {
	return AutotestserviceLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AutotestserviceLogic) Autotestservice(req types.RequestTestList) (*types.TestItemListResponse, error) {
	jklog.L().Debugln("request of model ", req.Model)

	res := &types.TestItemListResponse{
		Code:    0,
		Message: "",
	}
	li, err := data.AutoTestTestItemGet(req.Model)
	if err != nil {
		res.Code = 10
		res.Message = err.Error()
		jklog.L().Errorln(err)
		return res, nil
	}
	res.Message = "success"
	res.TestIList = *li

	return res, nil
}
